<template>
  <div class="article">
    <!-- banner轮播图 -->
    <Banner :banners="banners"></Banner>

    <!-- 文字列表 -->
    <div class="articleList">
      <div class="item" v-for="item of articles" :key="item._id">
        <div class="itemHeader">
          <div>
            <img :src="item.avatar" alt="" />
            <span>{{ item.date }}</span>
          </div>
          <h2>{{ item.title }}</h2>
        </div>
        <div class="itemContent">
            <img :src="item.headImgSrc" alt="" @click="goDetail(item._id)">
            <div class="content">{{item.content}}</div>
            <div class="more">
                <img src="../../assets/images/icon/chat1.png" alt="">
                <span>{{item.collectNum}}</span>
                <img src="../../assets/images/icon/view.png" alt="">
                <span>{{item.reading}}</span>
            </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import Banner from "../../components/Banner.vue";
export default {
  data() {
    return {
      articles: [],
      banners: [],
    };
  },
  components: {
    Banner,
  },
  mounted() {
    this.$http(`http://122.112.161.135:4000/api/article`).then((res) => {
      this.articles = res.data.res;
      this.banners = this.articles.map((item) => {
        var obj = {
          imageUrl: item.imgSrc,
        };
        return obj;
      });
    });
  },
  methods: {
      goDetail(id){
          this.$router.push(`/article/detail/${id}`)
      }
  },
};
</script>

<style scoped>
.banner {
  height: 6rem;
}
.articleList{
    background-color: #f8f8f8;
}
.item{
    margin: 0.5rem 0;
    background-color: #fff;
    border-top: 1px solid #ccc;
    border-bottom: 1px solid #ccc;
}
.itemHeader {
  padding: 0.2rem 0.4rem;
}
.itemHeader>div{
    display: flex;
    align-items: center;
}
.itemHeader img {
  width: 1rem;
  margin-right: 0.5rem;
}
.itemHeader h2{
    font-size: 0.5rem;
    font-weight: 700;
    margin: 0.2rem 0;
}
.itemContent img{
    width: 100%;
    height: 6rem;
}
.content{
    padding: 0.3rem 0.2rem;
    font-size: 0.3rem;
    color: #666;
}
.more{
    margin-bottom: 0.2rem;
}
.more img{
    width: 0.4rem;
    height: 0.4rem;
    margin:  0 0.3rem;
}
.more span{
    font-size: 0.2rem;
    margin-right: 0.2rem;
}
</style>